//
//  YAYIAppointView.m
//  YAYIDoctor
//
//  Created by hxp on 16/5/3.
//  Copyright © 2016年 hxp. All rights reserved.
//

#import "YAYIAppointView.h"

@implementation YAYIAppointView


-(void)setModel:(YAYIOrderPatientModel *)model
{
    _model = model;
    
    self.time.text  = [self periodWithTimStamp:[model.starttime integerValue] timeLong:[model.timelong integerValue]];
    
    self.service.text = [NSString  stringWithFormat:@"服务项目：%@",model.services];
    self.place.text = [NSString  stringWithFormat:@"就诊地点：%@",model.hospital];
    self.typeLbl.text = [model.isfirst integerValue] == 0 ? @"初诊" : @"复诊";
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //  self.backgroundColor = [UIColor redColor];
        [self creatViews];
        
    }
    return self;
}


-(void)creatViews
{
    if (self.time == nil) {
        self.time = [UILabel new];
        self.time.textColor = [UIColor lightGrayColor];
        self.time.font = [UIFont systemFontOfSize:font14];
        [self addSubview:self.time];
    }
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(18));
        make.left.equalTo(@(8));
        make.size.mas_equalTo(CGSizeMake(100, 20));
    }];
    if (self.service == nil) {
        self.service = [UILabel new];
        self.service.textColor = [UIColor lightGrayColor];
        self.service.font = [UIFont systemFontOfSize:font14];
        [self addSubview:self.service];
    }
    [self.service mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.time.mas_bottom).with.offset(10);
        make.left.mas_equalTo(self.time.mas_left);
        make.size.mas_equalTo(CGSizeMake(260, 20));
    }];
    if (self.place == nil) {
        self.place = [UILabel new];
        self.place.textColor = [UIColor lightGrayColor];
        self.place.font = [UIFont systemFontOfSize:font14];
        [self addSubview:self.place];
    }
    [self.place mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.service.mas_bottom).with.offset(10);
        make.left.mas_equalTo(self.time.mas_left);
        make.size.mas_equalTo(CGSizeMake(260, 20));
    }];
    if (self.title == nil) {
        self.title = [UILabel new];
        self.title.textColor = YAYIColor(83, 165, 243);
        self.title.font = [UIFont systemFontOfSize:font14];
        [self  addSubview:self.title];
    }
    [self.title  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.time.mas_top).with.offset(4);
        make.right.mas_equalTo(self.mas_right).with.offset(-18);
        make.size.mas_equalTo(CGSizeMake(40, 18));
        
    }];
    if (self.money == nil) {
        self.money = [UILabel new];
        self.money.textColor = YAYIColor(83, 165, 243);
        self.money.font = [UIFont systemFontOfSize:font14];
        [self  addSubview:self.money];
    }
    [self.money  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.title.mas_bottom).with.offset(4);
        make.right.mas_equalTo(self.mas_right).with.offset(-18);
        make.size.mas_equalTo(CGSizeMake(40, 18));
        
    }];
    
    
    // 状态，圆形图标
    UIView *typeView = [[UIView alloc] init];
    typeView.layer.borderWidth = 1.3;
    typeView.layer.borderColor = YAYIColor(92, 169, 239).CGColor;
    typeView.layer.masksToBounds = YES;
    typeView.layer.cornerRadius = 19;
    [self addSubview:typeView];
    [typeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(25);
        make.right.mas_offset(-10);
        make.width.height.mas_offset(38);
    }];
    
    
    UILabel *typeLbl = [[UILabel alloc] init];
    typeLbl.font = [UIFont systemFontOfSize:14];
    typeLbl.textColor = YAYIColor(92, 169, 239);
    typeLbl.textAlignment = NSTextAlignmentCenter;
    [typeView addSubview:typeLbl];
    self.typeLbl = typeLbl;
    [typeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(typeView);
    }];
    
}


#pragma mark - 工具方法
- (NSString *)periodWithTimStamp:(NSInteger)timeStamp timeLong:(NSInteger)timeLong
{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"HH:mm";
    
    NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:timeStamp];
    NSDate *endDate = [NSDate dateWithTimeIntervalSince1970:timeStamp + timeLong];
    NSString *startTimeStr = [formatter stringFromDate:startDate];
    NSString *endTimeStr = [formatter stringFromDate:endDate];
    
    return [NSString stringWithFormat:@"%@ - %@", startTimeStr, endTimeStr];
}



@end
